package View;


import Request.StudentRequest;
import Reservice.TableDTO;
import Service.Student;
import Service.impl.Studen;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
//管理员界面
public class ZhuJieMian {

    private int pagnow=1;
    private int pagSize=10;
   static JFrame jf=new JFrame("学生评教系统");
   static JTextField searchTxt=new JTextField(15);
    public void into() {
        jf.setSize(1000,400);
        jf.setLocationRelativeTo(null);
        jf.setResizable(false);
        JMenuBar jmb=new JMenuBar();
        JMenu ju=new JMenu("设置");
        JMenuItem m1=new JMenuItem("切换账号");
        JMenuItem m2=new JMenuItem("退出程序");

        ju.add(m1);
        ju.add(m2);
        jmb.add(ju);
        m1.addActionListener(new qiehuanJT());
        m2.addActionListener(new tuichuJT());
        jf.setJMenuBar(jmb);
//设置分割条
        JSplitPane sp=new JSplitPane();
        sp.setContinuousLayout(true);
        sp.setDividerLocation(65);
        sp.setDividerSize(1);
        sp.setEnabled(false);

        Box b= Box.createVerticalBox();
        JButton tianjia=new JButton("添加");
        tianjia.addActionListener(new tianjiaJT());
        JButton shanchu=new JButton("删除");
        shanchu.addActionListener(new shanchuJT());
        JButton xiugai=new JButton("修改");
        xiugai.addActionListener(new xiugaiJT());
        JButton chaxun=new JButton("查询");
        chaxun.addActionListener(new chaxunJT());

        JLabel caozuo=new JLabel("信息操作");

        b.add(Box.createVerticalStrut(30));
        b.add(caozuo);
        b.add(Box.createVerticalStrut(5));
        b.add(tianjia);
        b.add(Box.createVerticalStrut(30));
        b.add(shanchu);
        b.add(Box.createVerticalStrut(30));
        b.add(xiugai);
        b.add(Box.createVerticalStrut(40));
        b.add(searchTxt);
        b.add(chaxun);
        b.add(Box.createVerticalStrut(150));
        sp.setLeftComponent(b);
        //右侧
        Box a= Box.createVerticalBox();
        Box shuju= Box.createHorizontalBox();
        JLabel jiaogonghao=new JLabel();
        JLabel xingming=new JLabel();
        JLabel xingbie=new JLabel();
        JLabel lianxi=new JLabel();

        shuju.add(jiaogonghao);
        shuju.add(Box.createHorizontalStrut(23));
        shuju.add(xingming);
        shuju.add(Box.createHorizontalStrut(23));
        shuju.add(xingbie);
        shuju.add(Box.createHorizontalStrut(23));
        shuju.add(lianxi);
        a.add(shuju);

        sp.setRightComponent(new Right());


        jf.add(sp);
        jf.setVisible(true);
    }
    public class tianjiaJT implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            new AddStudent();
        }
    }
    public class qiehuanJT implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            new Login().zb();
            jf.dispose();
        }
    }
    public class chaxunJT implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            new ZhuJieMian().setPagnow(100);
            ZhuJieMian.reloadTable();
        }
    }

    public static void reloadTable() {
        Student student=new Studen();
        StudentRequest request=new StudentRequest();
        request.setPageNow(1);
        request.setPageSize(100);
        request.setSearchKey(searchTxt.getText().trim());
//        request.setSearchKey(getToolTipText().trim());
        TableDTO tableDTO = student.retrieveStudents(request);
        Vector<Vector<Object>>data=tableDTO.getData();
        new jiaoshi().updatem(data);
    }

    public class tuichuJT implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    }

    public static void main(String[] args) {
        new ZhuJieMian().into();
    }

    public void setPagnow(int pagnow) {
        this.pagnow = pagnow;
    }
    public class shanchuJT implements ActionListener {
        public void actionPerformed(ActionEvent e){
            new delet();
        }
    }
    public class xiugaiJT implements ActionListener {
        public void actionPerformed(ActionEvent e){
            new Revise();
        }
    }
}
